﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class DENGLU2 : System.Web.UI.Page
{
    DataClassesDataContext db = new DataClassesDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        string useType = DropDownList1.SelectedValue;
        string userName = txtusername.Text.Trim();
        string userPas = txtPassword.Text.Trim();
        //Response.Write("<script>alert("+userName+userPas+");</script>");

        var result = from r in db.Users
                     where r.UserName == userName
                     select r.UserPass;
        //Response.Write("<script>alert(" + result.First() + ");</script>");
        try
        {
            if (result.First().ToString().Trim() == userPas)
            {
                HttpCookie cookie = new HttpCookie("name");
                cookie.Value = userName;
                cookie.Expires = DateTime.Now.AddDays(1);
                Response.Cookies.Add(cookie);
                if (useType == "管理员")
                {
                    Response.Redirect("AddPro.aspx");
                }
                else
                {
                    Response.Redirect("select.aspx");
                }

            }
            else {
                Response.Write("<script>alert('输入密码错误!');</script>");
            }
        }
        catch
        {
            Response.Write("<script>alert('用户不存在!');</script>");
        }
        finally {
        }       
    }


    protected void btnReset_Click(object sender, EventArgs e)
    {
        txtPassword.Text = "";
        txtusername.Text = "";
    }
}